<template>
  <div class="app-container">
    <el-form
      ref="form"
      :inline="true"
      :model="formData"
      class="demo-form-inline"
    >
      <el-form-item label="用户ID">
        <el-input
          v-model="formData.recommendId"
          placeholder="请输入用户ID"
        ></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="formData.status" placeholder="请选择">
          <el-option
            v-for="item in regionDistributorStatusList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="类型">
        <el-select v-model="formData.type" placeholder="请选择">
          <el-option
            v-for="item in regionDistributorTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="onSearch">搜索</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="list" style="width: 100%">
      <!-- <el-table-column prop="orderId" label="订单ID" width="180">
      </el-table-column> -->
      <el-table-column prop="recommendId" label="用户ID" width="180">
      </el-table-column>
      <el-table-column prop="recommendUserName" label="用户名" width="120">
      </el-table-column>
      <el-table-column prop="totalPrice" label="总金额" width="120">
      </el-table-column>
      <el-table-column prop="promotionProfit" label="实际金额">
      </el-table-column>
      <el-table-column prop="shareRatio" label="佣金比例"> </el-table-column>

      <!-- <el-table-column prop="status" label="类型">
        <template slot-scope="scope">
          {{ regionDistributorTypeMap[scope.row.type] }}
        </template>
      </el-table-column> -->

      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          {{ regionDistributorStatusMap[scope.row.status] }}
        </template>
      </el-table-column>

      <el-table-column prop="remark" label="备注"> </el-table-column>
      <el-table-column prop="updateBy" label="操作人"> </el-table-column>
      <el-table-column prop="updateTime" label="更新时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="100" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 0"
            type="text"
            size="small"
            @click="audit(scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="queryParams.total > 0"
      :total="queryParams.total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.pageSize"
      @pagination="getListData"
    />

    <el-dialog title="提现审核" :visible.sync="dialogVisible" width="500px">
      <el-form
        ref="form"
        :rules="rules"
        :model="dialogFormData"
        label-width="120px"
      >
        <el-form-item label="审核状态" prop="status">
          <el-radio-group v-model="dialogFormData.status">
            <el-radio key="1" label="1">成功</el-radio>
            <el-radio key="2" label="2">失败</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核备注">
          <el-input
            type="textarea"
            v-model="dialogFormData.auditRemark"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getWithdrawList, auditWithdraw } from "@/api/customer/index";
import {
  regionDistributorTypeMap,
  regionDistributorTypeList,
  regionDistributorStatusMap,
  regionDistributorStatusList,
} from "@/config/index";
export default {
  name: "Index",
  data() {
    return {
      queryParams: {
        page: 0,
        pageSize: 10,
        total: 0,
      },
      formData: {
        recommendId: "",
        status: "",
        // type: "",
      },
      list: [],
      regionDistributorTypeMap,
      regionDistributorTypeList,
      regionDistributorStatusMap,
      regionDistributorStatusList,

      dialogVisible: false,
      dialogFormData: {
        status: "",
        auditRemark: "",
      },
      rules: {
        status: [
          { required: true, message: "请选择审核状态", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getListData({
      page: 1,
      limit: 10,
    });
  },
  methods: {
    getListData({ page, limit }) {
      getWithdrawList(
        {
          ...this.queryParams,
          type: 2,
        },
        page || this.queryParams.page + 1,
        limit
      ).then(({ data }) => {
        this.list = data.records;
        this.queryParams.total = data.total;
        this.queryParams.page = data.current;
        this.queryParams.limit = data.size;
      });
    },
    onSearch() {
      this.queryParams = {
        ...this.queryParams,
        ...this.formData,
      };
      this.getListData({
        page: 1,
        limit: 10,
      });
    },
    reset() {
      this.formData = {
        recommendId: "",
        status: "",
        // type: "",
      };
    },
    audit(item) {
      this.dialogFormData = {
        id: item.id,
        status: "",
        auditRemark: "",
      };
      this.$refs.form.clearValidate();
      this.dialogVisible = true;
    },
    submit() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.loading = true;
          await auditWithdraw({
            id: this.dialogFormData.id,
            status: this.dialogFormData.status,
            remark: this.dialogFormData.auditRemark,
          });
          this.$message.success("审核成功");
          this.dialogVisible = false;
          this.getListData({
            page: 1,
            limit: 10,
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.create {
  margin-bottom: 20px;
}
</style>
